#include "customer.hpp"

static double amountFor(Rental &ren)
{
  double thisAmount;
  switch(ren.getMovie().getPriceCode()){
      case Movie::REGULAR:
        thisAmount+=2;
        if(ren.getDaysRented() > 2) {
          thisAmount += (ren.getDaysRented() - 2) * 1.5;
        }
        break;
      case Movie::NEW_RELEASE:
        thisAmount += 1.5;
        if(ren.getDaysRented() > 3) {
          thisAmount += (ren.getDaysRented() - 3) * 1.5;
        }
        break;
      case Movie::CHILDRENS:
        thisAmount += 1.5;
        if(ren.getDaysRented() > 3) {
          thisAmount += (ren.getDaysRented() - 3) * 1.5;
        }
        break;
    }
  return thisAmount;
}

string Customer::statement() {
  double totalAmount = 0;
  int frequentRenterPoints = 0;
  auto rentIt = _rental.begin();
  string result = "Rental Record for" + getName() + "\n";
  while(rentIt != _rental.end()){
    double thisAmount = 0;
    Rental &ren = *rentIt;

    // datermine amounts for each line
    thisAmount = amountFor(ren);
    
    // add frequent renter points
    frequentRenterPoints++;

    // add bonus for a two day new release rental
    if((ren.getMovie().getPriceCode() == Movie::NEW_RELEASE) && 
        ren.getDaysRented() > 1)
      frequentRenterPoints ++;
    
    // show figure for this rental
    result += "\t" + ren.getMovie().getTitle() + "\t" + to_string(thisAmount) + "\n";
    totalAmount += thisAmount;

    rentIt++;
  }
  // add footer lines
  result += "Amount owed is" + to_string(totalAmount) + "\n";
  result += "You earned " + to_string(frequentRenterPoints) + " frequent renter points";

  return result;
}




